<?php

namespace Drupal\shusy_product_category\ViewsController;

use Drupal\shusy_product_category\ViewsController\handler\field\ShusyProductCategoryCategoriesViewsField;
use Drupal\shusy_product_category\ViewsController\handler\field\ShusyProductCategoryEditLinkViewsField;
use Drupal\shusy_product_category\ViewsController\handler\filter\ShusyProductCategoryCategoriesViewsFilter;
use EntityDefaultViewsController;


class ShusyProductCategoryViewsController extends EntityDefaultViewsController {

  public function views_data() {
    $data = parent::views_data();
    if (!empty($this->info['base table'])) {
      $table = $this->info['base table'];
      $info = [];

      $info[$table]['edit_link'] = [
        'title' => t('编辑'),
        'help' => t('编辑.'),
        'field' => [
          'handler' => ShusyProductCategoryEditLinkViewsField::class,
        ],
      ];


      $info[$table]['table'] = [
        'join' => [
          'shusy_product' => [
            'left_field' => 'id',
            'field' => 'product_id',
          ],
        ],
      ];
      $info[$table]['category'] = [
        'title' => t('分类'),
        'help' => t('分类.'),
        'field' => [
          'handler' => ShusyProductCategoryCategoriesViewsField::class,
          'no group by' => TRUE,
        ],
        'filter' => [
          'handler' => ShusyProductCategoryCategoriesViewsFilter::class,
        ],
      ];


      $data = drupal_array_merge_deep($data, $info);
    }
    return $data;
  }
}
